#include <math.h>
#include <iostream>
using std::cout;
using std::endl;

//前向声明
//让编译器知道Point类
//可以利用Point引用或者Point指针作为函数形参
//但是在读到Point完整定义之前不能使用Point的具体的成员
class Point;

class Line
{
public:
    double distance(const Point & p1,const Point & p2);
    void setPoint(Point & p1);
};

class Point{
public:
    Point(int x, int y)
    : _ix(x)
    , _iy(y)
    {}

    void print() const{
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
    
    //将Line的一个成员函数声明为Point类的友元函数
    //那么这个函数中可以通过Point对象访问Point类私有的成员
    friend
    double Line::distance(const Point & p1,const Point & p2);
    friend
    void Line::setPoint(Point & p1);
private:
    int _ix;
    int _iy;
};

double Line::distance(const Point & p1,const Point & p2){
    return sqrt(pow(p1._ix - p2._ix,2) + 
                pow(p1._iy - p2._iy,2));
}

void Line::setPoint(Point & p1){
    p1._ix = 100;
}

void test0(){
    Point pt1(0,0);
    Point pt2(3,4);
    Line ll;
    cout << ll.distance(pt1,pt2) << endl;
    ll.setPoint(pt1);
    pt1.print();
}

int main(void){
    test0();
    return 0;
}
